<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>下载进度条</title>
    <style>
        .progress {
            height: 25px;
            width: 400px;
            border-radius: 15px;
            background-color: #272425;
            border: 3px solid #272425;
            box-sizing: border-box;
            margin-bottom: 30px;
        }

        .inner {
            width: 30%;
            height: 20px;
            border-radius: 10px;
            text-align: right;
            position: relative;
            background-color: #409eff;
            background-size: 20px 20px;
            box-sizing: border-box;
            /*动画效果*/
            transition: all 100ms;
        }

        .inner span {
            position: absolute;
            right: -20px;
            bottom: -25px;
        }
    </style>
</head>
<body>
<div id="app">
    <!-- 外层盒子底色 （黑色） -->
    <div class="progress">
        <!-- 内层盒子 - 进度（蓝色） -->
        <div class="inner" :style="{width: progress+'%'}">
            <span>{{progress}}%</span>
        </div>
    </div>
    <button @click="start()">开始下载</button>
    <button @click="stop()">暂停下载</button>
    <button @click="cancel()" v-show="progress !== 100">取消下载</button>
</div>
</body>
<script src="js/vue.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            progress: 0,
            // 定时器对象
            timer: null
        },
        methods: {
            start() {
                this.timer = setInterval(() => {
                    if (this.progress < 100) {
                        this.progress++;
                    } else {
                        clearInterval(this.timer);
                    }
                }, 100)
            },
            stop() {
                // 直接让清除定时任务
                clearInterval(this.timer)
            },
            cancel() {
                this.progress = 0;
                clearInterval(this.timer)
            }
        }
    })
</script>
</html>